const express = require('express')
const router = express.Router()
const progressStore = require('../utils/progressStore')

// 获取进度状态
router.get('/:taskId', (req, res) => {
  const progress = progressStore.getProgress(req.params.taskId)
  
  if (!progress) {
    return res.status(404).json({
      success: false,
      message: '任务不存在或已过期'
    })
  }
  
  res.json({
    success: true,
    data: progress
  })
})

// 取消任务
router.post('/:taskId/cancel', (req, res) => {
  const success = progressStore.cancelTask(req.params.taskId)
  
  if (!success) {
    return res.status(404).json({
      success: false,
      message: '任务不存在或已过期'
    })
  }
  
  res.json({
    success: true,
    message: '任务已取消'
  })
})

module.exports = router